import { defineStore } from 'pinia'
import { CrudSchema } from '@/hooks/web/useCrudSchemas'

export interface SelectedItem {
  id: string
  title: string
}

// 定义一个函数来创建store的ID
function createPreViewDialogStoreId(id) {
  return `preViewDialog-${id}`
}

export const preViewDialogStore = (id) =>
  defineStore(createPreViewDialogStoreId(id), {
    state: () => ({
      isPreViewVisible: false,
      schema: <CrudSchema>[],
      src: ''
    }),
    actions: {
      openDialog() {
        this.isPreViewVisible = true
      },
      closeDialog() {
        this.isPreViewVisible = false
      },
      setSchema(newSchema) {
        this.schema = newSchema
      },
      reset() {
        this.$reset()
      }
    }
  })()
export type createPreViewDialogStoreType = ReturnType<typeof preViewDialogStore>
